package com.cxy.instarsystem.service;

import com.cxy.instarsystem.dao.MaterialRepository;
import com.cxy.instarsystem.po.MCategory;
import com.cxy.instarsystem.po.Material;
import com.cxy.instarsystem.po.Video;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.*;
import java.util.ArrayList;
import java.util.List;

@Service
public class DataServiceImpl implements DataService {

    @Autowired
    private MaterialRepository materialRepository;

    @Override
    public Page<Material> materialList(Pageable pageable,String mid) {
        return materialRepository.findAll(new Specification<Material>() {
            @Override
            public Predicate toPredicate(Root<Material> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
                Join join = root.join("mCategory");
                return cb.equal(join.get("id"), mid);
            }
        }, pageable);

    }
}
